import {Application} from 'egg';
import {
    indexRule,
    createRule,
    updateRule,
    destroyRule,
} from '../validate/goods/keywords';

/**
 * 关键词
 */
export default (app: Application) => {

    console.log(createRule);
    const {auth} = app.middleware;
    const {jwt} = app;
    return {

        'goods.keywords.list': {
            method: 'GET',
            path: '/api/goods/keywords',
            options: {
                tags: ['keywords/list'],
                description: '关键词列表',
                handler: app.controller.goods.keywords.list,
                middlewares: [jwt, auth('goods.keywords.list')],
                validate: indexRule,
            },
        },
        'goods.keywords.create': {
            method: 'POST',
            path: '/api/goods/keywords',
            options: {
                tags: ['keywords/create'],
                description: '创建关键词',
                handler: app.controller.goods.keywords.create,
                middlewares: [jwt, auth('goods.keywords.create')],
                validate: createRule,
            },
        },
        'goods.keywords.update': {
            method: 'PUT',
            path: '/api/goods/keywords/:id',
            options: {
                tags: ['keywords/update'],
                description: '更新关键词',
                handler: app.controller.goods.keywords.update,
                middlewares: [jwt, auth('goods.keywords.update')],
                validate: updateRule,
            },
        },
        'goods.keywords.destroy': {
            method: 'DELETE',
            path: '/api/goods/keywords/:id',
            options: {
                tags: ['keywords/delete'],
                description: '删除关键词',
                handler: app.controller.goods.keywords.destroy,
                middlewares: [jwt, auth('goods.keywords.destroy')],
                validate: destroyRule,
            },
        }
    };
};
